package com.cskaoyan.controller.admin.usercontroller;

import com.cskaoyan.service.userservice.AddressService;
import com.cskaoyan.service.userservice.UserService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.uservo.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hsp
 * @date 2021/5/8 21:54
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;
    @Autowired
    AddressService addressService;

    /**
     * admin/user/list?page=1&limit=20&sort=add_time&order=desc
     *
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return {
     * "errno": 0,
     * "data": {
     * "total": 3,
     * "items": [
     * {
     * "id": 1,
     * "username": "test1",
     * "password": "$2a$10$3joHPif3l/wsyKqxZA8aieZGQCWFcibfEtSJhAFLGovRPdtruDOuO",
     * "gender": 0,
     * "birthday": "2020-04-29",
     * "lastLoginTime": "2020-04-27 20:15:47",
     * "lastLoginIp": "",
     * "userLevel": 0,
     * "nickname": "测试用户",
     * "mobile": "13554556544",
     * "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80",
     * "weixinOpenid": "",
     * "status": 0,
     * "deleted": false
     * },
     * {
     * "id": 2,
     * "username": "test2",
     * "password": "$2a$10$.BYJMrQgkQwJ4bCT0Eo.7uVJAmii8e02fNItEcmE4s5kW2msBlC62",
     * "gender": 0,
     * "birthday": "2020-04-29",
     * "lastLoginTime": "2020-04-27 20:15:47",
     * "lastLoginIp": "",
     * "userLevel": 0,
     * "nickname": "测试用户2",
     * "mobile": "18654566544",
     * "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80",
     * "weixinOpenid": "",
     * "status": 0,
     * "deleted": false
     * },
     * {
     * "id": 3,
     * "username": "test3",
     * "password": "$2a$10$VudVULCgchGPjO9dnYeklOpXI4atzkLm1e6VMAcjxAkhXuHgdHh6K",
     * "gender": 0,
     * "birthday": "2020-04-29",
     * "lastLoginTime": "2020-04-27 20:15:47",
     * "lastLoginIp": "",
     * "userLevel": 0,
     * "nickname": "测试用户3",
     * "mobile": "18654566544",
     * "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80",
     * "weixinOpenid": "",
     * "status": 0,
     * "deleted": false
     * }
     * ]
     * },
     * "errmsg": "成功"
     * }
     */
    @RequiresPermissions("admin:user:list")
    @RequestMapping("admin/user/list")//admin/user/list?page=1&limit=20&sort=add_time&order=desc
    public BaseRespVo list(Integer page, Integer limit, String username, String mobile, String sort, String order) {

        UserVo userVo = userService.query(page, limit, username, mobile, sort, order);

        return BaseRespVo.ok(userVo);
    }

    @RequiresPermissions("admin:address:list")
    @RequestMapping("admin/address/list") //收货人名称、用户Id
    public BaseRespVo addressList(Integer page, Integer limit, String name, Integer userId, String sort, String order) {
        AddressListVo addressListVo = addressService.addressList(page, limit, name, userId, sort, order);
        return BaseRespVo.ok(addressListVo);
    }

    /**
     * 查看收藏
     */

    @RequiresPermissions("admin:collect:list")
    @RequestMapping("admin/collect/list") //用户id、商品id
    public BaseRespVo collectList(Integer page, Integer limit, Integer userId, Integer valueId, String sort, String order) {
        CollectVo collectVo = userService.collectList(page, limit, userId, valueId, sort, order);
        return BaseRespVo.ok(collectVo);
    }
    @RequiresPermissions("admin:footprint:list")
    @RequestMapping("admin/footprint/list") //用户id、商品id
    public BaseRespVo footprintList(Integer page, Integer limit, Integer userId, Integer goodsId, String sort, String order) {
        FootPrintVo footPrintVo = userService.footprintList(page, limit, userId, goodsId, sort, order);
        return BaseRespVo.ok(footPrintVo);
    }

    @RequiresPermissions("admin:history:list")
    @RequestMapping("admin/history/list")
    public BaseRespVo historyList(Integer page, Integer limit, Integer userId, String keyword, String sort, String order) {
        SearchHistoryVo searchHistoryVo = userService.historyList(page,limit,userId, keyword,sort,order);
        return BaseRespVo.ok(searchHistoryVo);
    }

    @RequiresPermissions("admin:feedback:list")
    @RequestMapping("admin/feedback/list") //用户名、反馈ID
    public BaseRespVo feedbackList(Integer page, Integer limit,String username,Integer Id, String sort, String order){

       FeedbackVo feedbackVo =  userService.feedbackList(page,limit,username,Id,sort,order);
       return BaseRespVo.ok(feedbackVo);
    }

}
